<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>打字机动画效果演示</title>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@300;400;500&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Inter', sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            color: #ffffff;
            overflow-x: hidden;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 40px 20px;
        }

        .header {
            text-align: center;
            margin-bottom: 80px;
            animation: fadeInUp 1s ease-out;
        }

        .header h1 {
            font-size: 3.5rem;
            font-weight: 700;
            margin-bottom: 16px;
            background: linear-gradient(135deg, #ffffff, #e0e7ff);
            background-clip: text;
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        .header p {
            font-size: 1.2rem;
            opacity: 0.9;
            font-weight: 300;
        }

        .demo-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
            gap: 40px;
            margin-bottom: 60px;
        }

        .demo-card {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(20px);
            border-radius: 20px;
            padding: 40px;
            border: 1px solid rgba(255, 255, 255, 0.2);
            transition: all 0.3s ease;
            animation: fadeInUp 1s ease-out;
        }

        .demo-card:hover {
            transform: translateY(-10px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
            border-color: rgba(255, 255, 255, 0.3);
        }

        .demo-title {
            font-size: 1.5rem;
            font-weight: 600;
            margin-bottom: 24px;
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .demo-title .material-icons {
            font-size: 28px;
            color: #60a5fa;
        }

        .demo-content {
            background: rgba(0, 0, 0, 0.2);
            padding: 30px;
            border-radius: 12px;
            font-family: 'JetBrains Mono', monospace;
            font-size: 1.1rem;
            line-height: 1.6;
            min-height: 120px;
            display: flex;
            align-items: center;
        }

        /* 基础打字机效果 */
        .typewriter-basic {
            overflow: hidden;
            border-right: 3px solid #60a5fa;
            white-space: nowrap;
            animation: typing 4s steps(50, end), blink-caret 0.75s step-end infinite;
        }

        @keyframes typing {
            from { width: 0 }
            to { width: 100% }
        }

        @keyframes blink-caret {
            from, to { border-color: transparent }
            50% { border-color: #60a5fa; }
        }

        /* 多行打字机效果 */
        .typewriter-multiline {
            height: 120px;
            overflow: hidden;
        }

        .typewriter-multiline .line {
            opacity: 0;
            animation: typewrite-line 1.5s ease-in-out forwards;
        }

        .typewriter-multiline .line:nth-child(1) { animation-delay: 0s; }
        .typewriter-multiline .line:nth-child(2) { animation-delay: 1.5s; }
        .typewriter-multiline .line:nth-child(3) { animation-delay: 3s; }

        @keyframes typewrite-line {
            0% { 
                opacity: 0; 
                transform: translateX(-20px);
            }
            50% { 
                opacity: 1; 
                transform: translateX(0);
            }
            100% { 
                opacity: 1; 
                transform: translateX(0);
            }
        }

        /* 彩色打字机效果 */
        .typewriter-colorful {
            overflow: hidden;
            border-right: 3px solid;
            border-color: #ef4444;
            white-space: nowrap;
            animation: typing-color 4s steps(40, end), 
                       color-change 4s ease-in-out,
                       blink-color-caret 0.75s step-end infinite;
        }

        @keyframes color-change {
            0% { color: #ef4444; border-color: #ef4444; }
            25% { color: #f59e0b; border-color: #f59e0b; }
            50% { color: #10b981; border-color: #10b981; }
            75% { color: #3b82f6; border-color: #3b82f6; }
            100% { color: #8b5cf6; border-color: #8b5cf6; }
        }

        @keyframes typing-color {
            from { width: 0 }
            to { width: 100% }
        }

        @keyframes blink-color-caret {
            from, to { border-color: transparent }
            50% { border-color: currentColor; }
        }

        /* 代码打字机效果 */
        .typewriter-code {
            background: #1f2937;
            color: #10b981;
            padding: 20px;
            border-radius: 8px;
            font-family: 'JetBrains Mono', monospace;
            position: relative;
            overflow: hidden;
        }

        .code-line {
            opacity: 0;
            transform: translateY(10px);
            animation: code-appear 0.8s ease-out forwards;
        }

        .code-line:nth-child(1) { animation-delay: 0.2s; }
        .code-line:nth-child(2) { animation-delay: 0.8s; }
        .code-line:nth-child(3) { animation-delay: 1.4s; }
        .code-line:nth-child(4) { animation-delay: 2s; }

        @keyframes code-appear {
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .keyword { color: #8b5cf6; }
        .string { color: #f59e0b; }
        .comment { color: #6b7280; font-style: italic; }

        /* 打字声音效果模拟 */
        .typewriter-sound {
            position: relative;
            overflow: hidden;
            border-right: 3px solid #06b6d4;
            white-space: nowrap;
            animation: typing-sound 5s steps(60, end), sound-blink 0.75s step-end infinite;
        }

        @keyframes typing-sound {
            from { width: 0 }
            to { width: 100% }
        }

        @keyframes sound-blink {
            from, to { border-color: transparent }
            50% { border-color: #06b6d4; }
        }

        .typewriter-sound::before {
            content: '';
            position: absolute;
            right: -8px;
            top: 50%;
            transform: translateY(-50%);
            width: 6px;
            height: 6px;
            background: #06b6d4;
            border-radius: 50%;
            animation: cursor-pulse 1s infinite;
        }

        @keyframes cursor-pulse {
            0%, 100% { opacity: 1; transform: translateY(-50%) scale(1); }
            50% { opacity: 0.5; transform: translateY(-50%) scale(1.2); }
        }

        /* 控制面板 */
        .control-panel {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(20px);
            border-radius: 20px;
            padding: 40px;
            border: 1px solid rgba(255, 255, 255, 0.2);
            text-align: center;
            animation: fadeInUp 1s ease-out 0.5s both;
        }

        .control-buttons {
            display: flex;
            gap: 16px;
            justify-content: center;
            flex-wrap: wrap;
            margin-top: 24px;
        }

        .control-btn {
            background: linear-gradient(135deg, #60a5fa, #3b82f6);
            border: none;
            padding: 12px 24px;
            border-radius: 50px;
            color: white;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .control-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 25px rgba(96, 165, 250, 0.4);
        }

        .control-btn:active {
            transform: translateY(0);
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .header h1 {
                font-size: 2.5rem;
            }

            .demo-grid {
                grid-template-columns: 1fr;
                gap: 24px;
            }

            .demo-card {
                padding: 24px;
            }

            .demo-content {
                font-size: 0.9rem;
                padding: 20px;
            }

            .container {
                padding: 20px 16px;
            }
        }

        /* 动画延迟 */
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        /* 自定义滚动条 */
        ::-webkit-scrollbar {
            width: 8px;
        }

        ::-webkit-scrollbar-track {
            background: rgba(255, 255, 255, 0.1);
        }

        ::-webkit-scrollbar-thumb {
            background: rgba(255, 255, 255, 0.3);
            border-radius: 4px;
        }

        ::-webkit-scrollbar-thumb:hover {
            background: rgba(255, 255, 255, 0.5);
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>打字机动画效果</h1>
            <p>CSS打字机效果集合</p>
        </div>

        <div class="demo-grid">
            <!-- 基础打字机效果 -->
            <div class="demo-card">
                <div class="demo-title">
                    <span class="material-icons">keyboard</span>
                    基础打字机效果
                </div>
                <div class="demo-content">
                    <div class="typewriter-basic" id="basic-text">
                        欢迎来到现代Web开发的世界！
                    </div>
                </div>
            </div>

            <!-- 多行打字机效果 -->
            <div class="demo-card">
                <div class="demo-title">
                    <span class="material-icons">view_headline</span>
                    多行打字机效果
                </div>
                <div class="demo-content">
                    <div class="typewriter-multiline" id="multiline-text">
                        <div class="line">第一行：创意无限</div>
                        <div class="line">第二行：技术驱动</div>
                        <div class="line">第三行：未来可期</div>
                    </div>
                </div>
            </div>

            <!-- 彩色打字机效果 -->
            <div class="demo-card">
                <div class="demo-title">
                    <span class="material-icons">palette</span>
                    彩色打字机效果
                </div>
                <div class="demo-content">
                    <div class="typewriter-colorful" id="colorful-text">
                        彩虹般的文字效果！
                    </div>
                </div>
            </div>

            <!-- 代码打字机效果 -->
            <div class="demo-card">
                <div class="demo-title">
                    <span class="material-icons">code</span>
                    代码打字机效果
                </div>
                <div class="demo-content">
                    <div class="typewriter-code">
                        <div class="code-line"><span class="keyword">function</span> <span class="string">createMagic</span>() {</div>
                        <div class="code-line">  <span class="keyword">const</span> magic = <span class="string">'CSS动画'</span>;</div>
                        <div class="code-line">  <span class="comment">// 让网页充满生命力</span></div>
                        <div class="code-line">}</div>
                    </div>
                </div>
            </div>

            <!-- 动态光标效果 -->
            <div class="demo-card">
                <div class="demo-title">
                    <span class="material-icons">radio_button_checked</span>
                    动态光标效果
                </div>
                <div class="demo-content">
                    <div class="typewriter-sound" id="sound-text">
                        体验真实的打字感觉，每一个字符都有生命力
                    </div>
                </div>
            </div>
        </div>

        <!-- 控制面板 -->
        <div class="control-panel">
            <h3>控制面板</h3>
            <p>点击按钮重新播放动画效果</p>
            <div class="control-buttons">
                <button class="control-btn" onclick="restartAnimation('basic')">
                    <span class="material-icons">refresh</span>
                    重启基础效果
                </button>
                <button class="control-btn" onclick="restartAnimation('multiline')">
                    <span class="material-icons">refresh</span>
                    重启多行效果
                </button>
                <button class="control-btn" onclick="restartAnimation('all')">
                    <span class="material-icons">refresh</span>
                    重启所有动画
                </button>
            </div>
        </div>
    </div>

    <script>
        // 动画控制脚本
        function restartAnimation(type) {
            if (type === 'basic' || type === 'all') {
                const basicElement = document.getElementById('basic-text');
                basicElement.style.animation = 'none';
                setTimeout(() => {
                    basicElement.style.animation = 'typing 4s steps(50, end), blink-caret 0.75s step-end infinite';
                }, 10);
            }

            if (type === 'multiline' || type === 'all') {
                const multilineElement = document.getElementById('multiline-text');
                const lines = multilineElement.querySelectorAll('.line');
                lines.forEach((line, index) => {
                    line.style.animation = 'none';
                    setTimeout(() => {
                        line.style.animation = `typewrite-line 1.5s ease-in-out forwards`;
                        line.style.animationDelay = `${index * 1.5}s`;
                    }, 10);
                });
            }

            if (type === 'all') {
                // 重启其他动画
                const colorfulElement = document.getElementById('colorful-text');
                colorfulElement.style.animation = 'none';
                setTimeout(() => {
                    colorfulElement.style.animation = 'typing-color 4s steps(40, end), color-change 4s ease-in-out, blink-color-caret 0.75s step-end infinite';
                }, 10);

                const soundElement = document.getElementById('sound-text');
                soundElement.style.animation = 'none';
                setTimeout(() => {
                    soundElement.style.animation = 'typing-sound 5s steps(60, end), sound-blink 0.75s step-end infinite';
                }, 10);
            }
        }

        // 页面加载完成后的初始化
        document.addEventListener('DOMContentLoaded', function() {
            // 添加页面加载动画
            const cards = document.querySelectorAll('.demo-card');
            cards.forEach((card, index) => {
                card.style.animationDelay = `${index * 0.2}s`;
            });

            // 模拟打字声音效果（可选）
            const soundText = document.getElementById('sound-text');
            if (soundText) {
                let currentChar = 0;
                const text = soundText.textContent;
                soundText.textContent = '';
                
                function typeChar() {
                    if (currentChar < text.length) {
                        soundText.textContent += text.charAt(currentChar);
                        currentChar++;
                        setTimeout(typeChar, 100);
                    }
                }
                
                setTimeout(() => {
                    typeChar();
                }, 2000);
            }
        });

        // 添加键盘快捷键支持
        document.addEventListener('keydown', function(event) {
            if (event.ctrlKey && event.key === 'r') {
                event.preventDefault();
                restartAnimation('all');
            }
        });

        // 添加鼠标悬停效果
        const demoCards = document.querySelectorAll('.demo-card');
        demoCards.forEach(card => {
            card.addEventListener('mouseenter', function() {
                this.style.transform = 'translateY(-15px) scale(1.02)';
            });
            
            card.addEventListener('mouseleave', function() {
                this.style.transform = 'translateY(0) scale(1)';
            });
        });

        // 响应式处理
        function handleResize() {
            const isMobile = window.innerWidth <= 768;
            const demoGrid = document.querySelector('.demo-grid');
            
            if (isMobile) {
                demoGrid.style.gridTemplateColumns = '1fr';
            } else {
                demoGrid.style.gridTemplateColumns = 'repeat(auto-fit, minmax(500px, 1fr))';
            }
        }

        window.addEventListener('resize', handleResize);
        handleResize(); // 初始调用
    </script>
</body>
</html>
